using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Events;

public class Trigger : MonoBehaviour
{
    public UnityEvent OnTrigger;
    public LayerMask targetLayer;
    AudioSource audioSource;

    private void Start()
    {
        audioSource = GetComponent<AudioSource>();
    }

    //private void Update()
    //{
    //    if (Input.GetKeyDown(KeyCode.C))
    //        OnTrigger.Invoke();
    //}

    void OnTriggerEnter2D(Collider2D collision)
    {        
        if ((1<<collision.gameObject.layer & targetLayer)!=0)
        {
            OnTrigger.Invoke();
            audioSource.Play();            
        }
    }
}
